package lesson4.pages;

import lesson4.api.ApplicationManager;
import lesson4.api.base.PageBase;
import lesson4.api.models.UserModel;
import lesson4.pages.locators.page.IndexPageLocators;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class IndexPage extends PageBase
{
	// Logger
	private static Logger log = LoggerFactory.getLogger(IndexPage.class);
	// Locators
	private final IndexPageLocators locators;

	public IndexPage(ApplicationManager p_app)
	{
		super(p_app);
		locators = new IndexPageLocators(p_app);
	}

	private void fillLoginData(UserModel p_userData)
	{
		// Login to site
		log.info("Enter login: " + p_userData.login);
		type(locators.txtLogin(), p_userData.login);
		log.info("Enter login: " + p_userData.password);
		type(locators.txtPassword(), p_userData.password);
	}

	private void submitLoginData()
	{
		log.info("Send login data");
		click(locators.btnLogin());
	}

	public void openRegistrationPage()
	{
		// Open the registration page
		log.info("Open Registration page by link on Index page");
		click(locators.linkRegistration());
	}

	public void login(UserModel p_userData)
	{
		fillLoginData(p_userData);
		submitLoginData();
	}

	public boolean isNotification()
	{
		log.info("Check for is notification about successfull registration");
		return isElementPresent(locators.blockNotification());
	}
}
